%% Comapring the EEF from CHAMP and JULIA
% following the paper by Alken Maus JASTP Volume 72, Issue 4, March 2010, Pages 319326 
% result : I got exactly the same result as Patrick in his paper. So the
% EEF from CHAMP and JULIA are higly correlated and has a slope close to 1

clear;
load /home/mnair/projects/longp/eef_data_mod.mat eef;
%eef matric description 
% # Field 1: fday
% # Field 2: longitude (degrees)
% # Field 3: latitude (degrees)
% # Field 4: local time (hours)
% # Field 5: season (day of year)
% # Field 6: eastward electric field (V/m)
% # Field 7: DC current shift (A/m)
% # Field 8: CHAMP peak current value (A/m)
% # Field 9: KP
% # Field 10: F10.7 (W/m^2)
% # Field 11: F10.7A (W/m^2)
% # Field 12: R^2 (coefficient of determination)
% # Field 13: R (correlation of CHAMP and model profiles)
% # Field 14: chi^2
% # Field 15: eefm model output 

%load /home/mnair/projects/longp/OMNI_ELEC_new ace_all;
load /home/mnair/projects/longp/aplist.mat; 
fday_ap = fday_ap - datenum(2000,1,1);
% load /home/mnair/projects/longp/alldays JULI_SEG ACE_SEG TIME_SEG;
% JULI_SEG = JULI_SEG.*24.366*1e-3; %mV/m
%load('/home/mnair/projects/ace_tensor/juliadata/Julia_2001_2011.mat');

load ([ '/home/mnair/projects/ace_tensor/ind_delh_array.mat']);

        
% TIME_SEG = reshape(Julia_fday_n',[1,1479*132]) - datenum(2000,1,1);
% JULI_SEG = reshape(Julia_W_n',[1,1479*132])*24.366*1e-3;

JULI_SEG = (5.2889 + 0.1947*india_climate_rem_delh_array + 0.0001*(india_climate_rem_delh_array).^2 -...
            0.0000021*(india_climate_rem_delh_array).^3) * 37000 / 1e6;
TIME_SEG = india_fday - datenum(2000,1,1);


% April 9, 2012
% When I compared india_delta_h with CHAMP , I got a could !!. Needs to
% investigae this further.

lt_start = 7;
lt_end = 16;

nd = 1;

nd = 1;
data_pair = [];

for i = 1:length(eef),
    
%      if ( eef(i,4) > lt_start & eef(i,4) < lt_end & ...
%              eef(i,2) < -66 & eef(i,2) > -86)

      if ( eef(i,4) > lt_start & eef(i,4) < lt_end & ...
              eef(i,2) < 88 & eef(i,2) > 68)

         
        
        [trash ind] = min(abs(TIME_SEG - eef(i,1)));
        if abs(trash) < 20/1440 & ~isnan(JULI_SEG(ind)) , % 10 minutes
           
            %fprintf('%d %6.4f\n',i, trash*1440);
            data_pair(nd,1) = JULI_SEG(ind);
            data_pair(nd,2) = eef(i,6)*1e3;
            data_pair(nd,3) = eef(i,15);
            nd = nd + 1;
        end
         
         
     end;
end;


     
         
         